#include <iostream>
#include <stdlib.h>
#include <vector>
#include <unordered_map>
#include "comm.hpp"



int main()
{
    std::string query = GetQuery();
    // a=100&b=200&c=300

    std::vector<std::string> query_kvs;
    while (true)
    {
        std::string kv;
        if (CutString(query, &kv, &query, "&")) {
            query_kvs.push_back(kv);
        }
        else {
            if (!query.empty())
                query_kvs.push_back(query);
            break;
        }
    }

    std::unordered_map<std::string, std::string> query_map;
    for (auto& kv : query_kvs)
        query_map.insert(GetKV(kv));

    int first_number = stoi(query_map["first_number"]);
    int second_number = stoi(query_map["second_number"]);

    // 通过管道发送给父进程
    std::cout << R"(<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">)"
        << "<title>结果</title>"
        << R"(<link rel="shortcut icon" href="favicon.ico" />)"
        << R"(<link rel="apple-touch-icon" href="favicon.ico" />)"
        << "</head><body>"
        << R"(<br>)"
        << R"(<a href="/">首页 </a>)"
        << R"(<a href="/login.html">登录注册 </a>)"
        << R"(<a href="/shell.html">远程连接 </a><br>)"
        << "<h2>计算结果</h2><br>"
        << "<h1>" << first_number << " + " << second_number << " = "
        << first_number + second_number << "</h1>"
        << "</body></html>" << std::endl;

    return 0;
}
